//
//  WSImageTextButton.m
//  LANGirl
//
//  Created by 吴帅 on 16/4/1.
//
//

#import "WSImageTextButton.h"

@interface WSImageTextButton ()

@property (nonatomic, strong) UIImageView *icoImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImage *upImage;
@property (nonatomic, strong) UIImage *downImage;

@end

@implementation WSImageTextButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
    self.icoImage = [[UIImageView alloc] init];
    [self addSubview:_icoImage];
    [self.icoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(@0);
        make.top.mas_equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(60 * AUTO_WIDTH, 60 * AUTO_WIDTH));
    }];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.font = [UIFont systemFontOfSize:TEXTCONTENTFONT2*AUTO_WIDTH];
    self.nameLabel.textColor = HS;
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(@0);
        make.top.equalTo(self.icoImage.mas_bottom);
        make.right.left.bottom.mas_equalTo(@0);
    }];
    
    [self addTarget:self action:@selector(selfTouchDown) forControlEvents:UIControlEventTouchDown];
    [self addTarget:self action:@selector(selfTouchUpInside) forControlEvents:UIControlEventTouchUpOutside];
}

- (void)setTitleStr:(NSString *)titleStr {
    
    _titleStr = titleStr;
    [self selfTouchUpInside];
    self.nameLabel.text = _titleStr;
}

- (void)setUpInsideWithImage:(UIImage *)upImage down:(UIImage *)downImage {

    self.upImage = upImage;
    if (!_downImage) {
        self.downImage = downImage;
    } else {
        self.downImage = upImage;
    }
    self.icoImage.image = _upImage;
}

- (void)selfTouchDown {
    
    self.icoImage.image = _downImage;
}

- (void)selfTouchUpInside {
    
    self.icoImage.image = _upImage;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
